<%@ page import="java.util.Calendar" %>
<%@ page import="java.util.GregorianCalendar" %><%--
  Created by IntelliJ IDEA.
  User: pkuschool
  Date: 2021/4/15
  Time: 5:22 下午
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>访问量统计</title>
</head>
<body>

<%
    response.setIntHeader("Refresh", 1);
    /*记录页面访问数据*/
    Integer hitCount = (Integer) application.getAttribute("hitCount");
    if (hitCount == null || hitCount == 0) {
        out.println("欢迎访问");
        hitCount = 1;
    } else {
        out.println("欢迎再次访问");
        hitCount++;
    }
    application.setAttribute("hitCount", hitCount);

    // 获取当前时间
    Calendar calendar = new GregorianCalendar();
    String am_pm;
    int hour = calendar.get(Calendar.HOUR);
    int minute = calendar.get(Calendar.MINUTE);
    int second = calendar.get(Calendar.SECOND);
    if(calendar.get(Calendar.AM_PM) == 0)
        am_pm = "AM";
    else
        am_pm = "PM";
    String CT = hour+":"+ minute +":"+ second +" "+ am_pm;
    out.println("当前时间为: " + CT + "\n");
%>

<p>hitCount:<% out.print(hitCount); %></p>

</body>
</html>
